// ------------------------------------------------------------------------------
// Copyright (c) 2015 Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ------------------------------------------------------------------------------

package com.onedrive.sdk.generated;

import com.onedrive.sdk.concurrency.*;
import com.onedrive.sdk.core.*;
import com.onedrive.sdk.extensions.*;
import com.onedrive.sdk.http.*;
import com.onedrive.sdk.generated.*;
import com.onedrive.sdk.options.*;
import com.onedrive.sdk.serializer.*;

import java.util.*;

import com.google.gson.JsonObject;
import com.google.gson.annotations.*;

// **NOTE** This file was generated by a tool and any changes will be overwritten.

/**
 * The class for the Base Item.
 */
public class BaseItem implements IJsonBackedObject {

    /**
     * The Created By.
     */
    @SerializedName("createdBy")
    public IdentitySet createdBy;

    /**
     * The Created Date Time.
     */
    @SerializedName("createdDateTime")
    public java.util.Calendar createdDateTime;

    /**
     * The CTag.
     */
    @SerializedName("cTag")
    public String cTag;

    /**
     * The Description.
     */
    @SerializedName("description")
    public String description;

    /**
     * The ETag.
     */
    @SerializedName("eTag")
    public String eTag;

    /**
     * The Id.
     */
    @SerializedName("id")
    public String id;

    /**
     * The Last Modified By.
     */
    @SerializedName("lastModifiedBy")
    public IdentitySet lastModifiedBy;

    /**
     * The Last Modified Date Time.
     */
    @SerializedName("lastModifiedDateTime")
    public java.util.Calendar lastModifiedDateTime;

    /**
     * The Name.
     */
    @SerializedName("name")
    public String name;

    /**
     * The Parent Reference.
     */
    @SerializedName("parentReference")
    public ItemReference parentReference;

    /**
     * The Size.
     */
    @SerializedName("size")
    public Long size;

    /**
     * The Web Url.
     */
    @SerializedName("webUrl")
    public String webUrl;

    /**
     * The Audio.
     */
    @SerializedName("audio")
    public Audio audio;

    /**
     * The Deleted.
     */
    @SerializedName("deleted")
    public Deleted deleted;

    /**
     * The File.
     */
    @SerializedName("file")
    public File file;

    /**
     * The File System Info.
     */
    @SerializedName("fileSystemInfo")
    public FileSystemInfo fileSystemInfo;

    /**
     * The Folder.
     */
    @SerializedName("folder")
    public Folder folder;

    /**
     * The Image.
     */
    @SerializedName("image")
    public Image image;

    /**
     * The Location.
     */
    @SerializedName("location")
    public Location location;

    /**
     * The Open With.
     */
    @SerializedName("openWith")
    public OpenWithSet openWith;

    /**
     * The Photo.
     */
    @SerializedName("photo")
    public Photo photo;

    /**
     * The Remote Item.
     */
    @SerializedName("remoteItem")
    public Item remoteItem;

    /**
     * The Search Result.
     */
    @SerializedName("searchResult")
    public SearchResult searchResult;

    /**
     * The Shared.
     */
    @SerializedName("shared")
    public Shared shared;

    /**
     * The Special Folder.
     */
    @SerializedName("specialFolder")
    public SpecialFolder specialFolder;

    /**
     * The Video.
     */
    @SerializedName("video")
    public Video video;

    /**
     * The Permissions.
     */
    public transient PermissionCollectionPage permissions;

    /**
     * The Versions.
     */
    public transient ItemCollectionPage versions;

    /**
     * The Children.
     */
    public transient ItemCollectionPage children;

    /**
     * The Thumbnails.
     */
    public transient ThumbnailSetCollectionPage thumbnails;


    /**
     * The raw representation of this class
     */
    private transient JsonObject mRawObject;

    /**
     * The serializer
     */
    private transient ISerializer mSerializer;

    /**
     * Gets the raw representation of this class
     * @return the raw representation of this class
     */
    public JsonObject getRawObject() {
        return mRawObject;
    }

    /**
     * Gets serializer
     * @return the serializer
     */
    protected ISerializer getSerializer() {
        return mSerializer;
    }

    /**
     * Sets the raw json object
     *
     * @param serializer The serializer
     * @param json The json object to set this object to
     */
    public void setRawObject(final ISerializer serializer, final JsonObject json) {
        mSerializer = serializer;
        mRawObject = json;


        if (json.has("permissions")) {
            final BasePermissionCollectionResponse response = new BasePermissionCollectionResponse();
            if (json.has("permissions@odata.nextLink")) {
                response.nextLink = json.get("permissions@odata.nextLink").getAsString();
            }

            final JsonObject[] sourceArray = serializer.deserializeObject(json.get("permissions").toString(), JsonObject[].class);
            final Permission[] array = new Permission[sourceArray.length];
            for (int i = 0; i < sourceArray.length; i++) {
                array[i] = serializer.deserializeObject(sourceArray[i].toString(), Permission.class);
                array[i].setRawObject(serializer, sourceArray[i]);
            }
            response.value = Arrays.asList(array);
            permissions = new PermissionCollectionPage(response, null);
        }

        if (json.has("versions")) {
            final BaseItemCollectionResponse response = new BaseItemCollectionResponse();
            if (json.has("versions@odata.nextLink")) {
                response.nextLink = json.get("versions@odata.nextLink").getAsString();
            }

            final JsonObject[] sourceArray = serializer.deserializeObject(json.get("versions").toString(), JsonObject[].class);
            final Item[] array = new Item[sourceArray.length];
            for (int i = 0; i < sourceArray.length; i++) {
                array[i] = serializer.deserializeObject(sourceArray[i].toString(), Item.class);
                array[i].setRawObject(serializer, sourceArray[i]);
            }
            response.value = Arrays.asList(array);
            versions = new ItemCollectionPage(response, null);
        }

        if (json.has("children")) {
            final BaseItemCollectionResponse response = new BaseItemCollectionResponse();
            if (json.has("children@odata.nextLink")) {
                response.nextLink = json.get("children@odata.nextLink").getAsString();
            }

            final JsonObject[] sourceArray = serializer.deserializeObject(json.get("children").toString(), JsonObject[].class);
            final Item[] array = new Item[sourceArray.length];
            for (int i = 0; i < sourceArray.length; i++) {
                array[i] = serializer.deserializeObject(sourceArray[i].toString(), Item.class);
                array[i].setRawObject(serializer, sourceArray[i]);
            }
            response.value = Arrays.asList(array);
            children = new ItemCollectionPage(response, null);
        }

        if (json.has("thumbnails")) {
            final BaseThumbnailSetCollectionResponse response = new BaseThumbnailSetCollectionResponse();
            if (json.has("thumbnails@odata.nextLink")) {
                response.nextLink = json.get("thumbnails@odata.nextLink").getAsString();
            }

            final JsonObject[] sourceArray = serializer.deserializeObject(json.get("thumbnails").toString(), JsonObject[].class);
            final ThumbnailSet[] array = new ThumbnailSet[sourceArray.length];
            for (int i = 0; i < sourceArray.length; i++) {
                array[i] = serializer.deserializeObject(sourceArray[i].toString(), ThumbnailSet.class);
                array[i].setRawObject(serializer, sourceArray[i]);
            }
            response.value = Arrays.asList(array);
            thumbnails = new ThumbnailSetCollectionPage(response, null);
        }
    }
}
